package javatuning.ch3;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@Warmup(iterations = 5,time = 5, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5,time = 5, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
public class BitMathBench {
    @Param({"2035"})
    private int param;

	@Benchmark
	@BenchmarkMode(Mode.Throughput)
	@Warmup(iterations = 2)
	@Measurement(iterations = 2)
	public int mathOp() throws IOException {
		param=param*2;
		param=param/2;
		return param;
	}

	@Benchmark
	@BenchmarkMode(Mode.Throughput)
	@Warmup(iterations = 2)
	@Measurement(iterations = 2)
	public int bitOp() throws IOException {
		param=param<<1;
		param=param>>1;
		return param;
	}


	public static void main(String[] args) throws Exception {
        Options opt = new OptionsBuilder()
                .include(BitMathBench.class.getSimpleName())
                .forks(1)
                .build();
        new Runner(opt).run();
	}
}
